/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.card;

import deatax.GameData;
import deatax.Player;
import deatax.Resource;
import java.util.ArrayList;

/**
 *
 * @author pson
 */
public class CardResourceTag extends CardEffect {

    @Override
    public void run(GameData data, String[] args) {
        ArrayList<Player> players = new ArrayList<Player>();
        if (args[0].equals("All")) {
            players.addAll(data.getRoster().getPlayers());
        } else if (args[0].equals("Self")) {
            players.add(data.getCurrentPlayer());
        } else if (args[0].equals("Other")) {
            players.addAll(data.getRoster().getPlayers());
            players.remove(data.getCurrentPlayer());
        }

        ArrayList<Resource> res = data.getGame().getTaggedResources(args[1]);
        int num = Integer.parseInt(args[2]);
        for (Player p : players) {
            for (Resource r : res) {

                int init = p.getResourceNum(r);
                int after = p.addResource(r, num);
                if (after < 0) {
                    after = 0;
                }
                if (num > 0) {
                    data.getGui().addMessage(p, "Receives a +" + num + " bonus to " + r.getName() + " (" + init + " > " + after + ")");
                } else {
                    data.getGui().addMessage(p, "Loses " + (-num) + " of their " + r.getName() + " (" + init + " > " + after + ")");
                }
            }
        }

    }
}